<?php
class Db{
	public $error;
	public $table;//操作的表
	public $opt=array(
		'where'=>'',
		'group'=>'',
		'limit'=>'',
		'order'=>'',
		'having'=>''
	);
	//添加数据
	public function insert($data){
		// INSERT INTO XX (title,click) values('后盾网',99);
		$field = array_keys($data);
		$value = array_values($data);
		$value = "'".implode("','",$value)."'";
		$sql = "INSERT INTO ".$this->table.'('.implode(',', $field).') VALUES('.$value.')';
		return $this->exe($sql);
	}
	//条件
	public function where($where){
		$this->opt['where']=" WHERE ".$where;
	}
	//查询
	public function select(){
		//select * from table where  group by having order limit ;
		$sql = "SELECT * FROM ".$this->table.$this->opt['where'].$this->opt['group'].$this->opt['having'].$this->opt['order'].$this->opt['limit'];
		return $this->query($sql);
	}
	//Limit
	public function limit($limit){
		$this->opt['limit']=" LIMIT ".$limit;
	}
	//修改
	public function update($data){
		//UPDATE TABLE  SET title='xx',click='xx';
		$sql = "UPDATE ".$this->table.' SET ';
		foreach($data as $field=>$value){
			$sql .=$field."='".$value."',";
		}
		$sql = substr($sql,0,-1).$this->opt['where'];
		return $this->exe($sql);
	}
	//删除
	public function delete(){
		//DELETE FROM table WHRE 
		$sql = "DELETE FROM ".$this->table.$this->opt['where'];
		return $this->exe($sql);
	}
}